﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace HomeRun.DB.RowState
{
  internal abstract class RowStateBase
  {
    protected List<object> values;
    public RowStateBase(DataRow row)
    {
        Table = row.Table.TableName;
        ID = (long)row["ID"];
        values = new List<object>();
    }
    public string Table
    {
      get;
      private set;
    }
    public long ID
    {
      get;
      private set;
    }
    public abstract bool Replay();

    protected void FillRowState(DataRow row)
    {
      DataTable table = HomeRunDB.Instance.Data.Tables[Table];
      foreach (DataColumn col in table.Columns)
      {
        values.Add(row[col]);
      }
    }
    protected DataRow FindRow()
    {
      DataRow retValue = null;
      DataTable table = HomeRunDB.Instance.Data.Tables[this.Table];
      if (table != null)
      {
        var query = from row in table.AsEnumerable()
                    where row.Field<long>("OID") == this.ID
                    select row;
        retValue = query.First();
      }
      return retValue;
    }
  }
}
